//
//  ViewController.m
//  17 -数据存储
//
//  Created by dllo on 16/8/5.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    NSLog(@"%@",docPath);
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *testDirectory = [docPath stringByAppendingPathComponent:@"test"];
    BOOL isCreated = [fileManager createDirectoryAtPath:testDirectory withIntermediateDirectories:YES attributes:nil error:nil];
    if (isCreated) {
        NSLog(@"创建文件夹成功");
    } else {
        NSLog(@"创建文件夹失败");
    }
    NSString *testPath = [testDirectory stringByAppendingPathComponent:@"test.txt"];
    BOOL res = [fileManager createFileAtPath:testPath contents:nil attributes:nil];
    if (res) {
        NSLog(@"创建文件成功");
    } else {
        NSLog(@"创建文件失败");
    }
    NSString *copyPath = [testDirectory stringByAppendingPathComponent:@"testYMJ3.txt"];
    BOOL  irest = [fileManager copyItemAtPath:testPath toPath:copyPath error:nil];
    if (irest) {
        NSLog(@"复制成功");
    } else {
        NSLog(@"复制失败");
    }
    NSString *movePath = [testDirectory stringByAppendingPathComponent:@"testMoved3.txt"];
    BOOL ismoved = [fileManager moveItemAtPath:copyPath toPath:movePath error:nil];
    if (ismoved) {
        NSLog(@"移动成功");
    } else {
        NSLog(@"移动失败");
    }
    BOOL rest =[fileManager removeItemAtPath:testPath error:nil];
    if (rest) {
        NSLog(@"删除成功");
    } else {
        NSLog(@"删除失败");
    }
    NSLog(@"文件是否存在:%@",[fileManager fileExistsAtPath:testPath] ? @"YES":@"NO");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
